'use strict'

const Controller = require('egg').Controller

class SysUserController extends Controller {
  async login() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.login(data)
  }

  async refreshToken() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.refreshToken(data)
  }

  async logout() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.logout(data)
  }

  async register() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.register(data)
  }

  async hasAdmin() {
    const { ctx, service } = this
    await service.sysUser.hasAdmin()
  }

  async getCaptcha() {
    const { ctx, service } = this
    await service.sysUser.getCaptcha()
  }

  async verifyToken() {
    const { ctx, service } = this
    const { header } = ctx.request
    const token = header.authorization.slice(7) || '' // Bearer的长度 + 1空格 = 7
    await service.sysUser.verifyToken(token)
  }

  async userList() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.userList(data)
  }

  async userUpdate() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.userUpdate(data)
  }

  async changeStatus() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.changeStatus(data)
  }

  async userDeactivate() {
    const { ctx, service } = this
    const data = ctx.request.body
    await service.sysUser.userDeactivate(data)
  }
}

module.exports = SysUserController
